package com.luping.xiao.xiao.utils.Thread;

import com.luping.xiao.xiao.domain.SysUser;
import com.luping.xiao.xiao.utils.ToolsUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 队列生产者
 */
public class ThreadRunProducer implements Runnable {
    protected static final Logger log = LoggerFactory.getLogger(ThreadRunProducer.class);
    private String name = "";

    private Integer age = 0;

    public ThreadRunProducer() {

    }

    public ThreadRunProducer(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public void run() {
        log.info("数据生产中..");
        List<SysUser> listUser = new ArrayList<>();
        Integer count=ToolsUtils.gatRandom();
        for (int i = 0; i < count; i++) {
            String nameN = ToolsUtils.getRandomCharString(3);
            Integer ageN = (int) Math.random() * 100;
            SysUser sysUser = new SysUser();
            sysUser.setAge(age + ageN);
            sysUser.setUserName(name + nameN);
            listUser.add(sysUser);
        }
        ThreadQueue.addQueue(listUser);
        log.info("ThreadQueue="+ThreadQueue.gatQueue().size());
        ThreadQueue.currentTaskStat = ThreadQueue.EXTRACTOR_STAT.ANALYSIS_DONE;
    }
}
